<?php
$i = 1;
// Check if a category as least exists
if(isset($categories) and !empty($categories))
{
    if(isset($forums) and !empty($forums))
    {
        foreach($categories as $category)
        {
        ?>
<table class="tborder" cellspacing="1" cellpadding="4" border="0">
    <thead>
        <tr>
            <td class="thead" colspan="5">
                    <div class="expcolimage">
                        <img alt="[-]" src="<?php echo MTemplate::getInstance()->getRelativeFolderPath();?>/img/collapse.gif" style="cursor: pointer;">
                    </div>

                    <div>
                        <strong><?php echo $category->name; ?></strong>
                        <br />
                        <div class="smalltext"></div>
                    </div>
            </td>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td class="tcat" width="35">&nbsp;</td>
            <td class="tcat"><strong>Forums</strong></td>
            <td class="tcat" width="85" align="center" style="white-space: nowrap;"><strong>Discussions</strong></td>
            <td class="tcat" width="85" align="center" style="white-space: nowrap;"><strong>Messages</strong></td>
            <td class="tcat" width="200" align="center"><strong>Derniers messages</strong></td>
        </tr>
        <?php
            foreach($forums as $forum)
            {
                if($forum->category === $category->id)
                {
                    $rowColor = ($i++ % 2 == 0) ? 'trow1' : 'trow2' ;
                ?>
                    <tr>
                        <td class="<?php echo $rowColor; ?>" valign="top" align="center">
                            <p><img src="<?php echo MTemplate::getInstance()->getRelativeFolderPath();?>/img/off.gif" alt="img"></p>
                        </td>
                        <td class="<?php echo $rowColor; ?>" valign="top">
                            <strong>
                                <a href="<?php echo __route('ml-forum/forums/show&f='.$forum->id); ?>">
                                    <?php echo $forum->name; ?>
                                </a>
                            </strong>
                            <div class="smalltext">
                                    <?php echo $forum->description; ?>
                            </div>
                        </td>
                        <td class="<?php echo $rowColor; ?>" valign="top" align="center" style="white-space: nowrap;">
                            <?php echo $forum->topics_number; ?>
                        </td>
                        <td class="<?php echo $rowColor; ?>" valign="top" align="center" style="white-space: nowrap;">
                            <?php echo $forum->posts_number; ?>
                        </td>
                        <td class="<?php echo $rowColor; ?>" valign="top" align="center" style="white-space: nowrap;">
                            <?php echo 'Last post id : [' . $forum->last_post_id.']' ; ?>
                        </td>
                    </tr>

                <?php
                }
            }
         ?>
         </tbody>
</table>
<br />
         <?php
        }
    }
}
else
{
    echo __t('mandrill.forum.forums.empty', array(), 'ml-forum', 'modules');
}
?>